package com.baizhi.service;

import com.baizhi.dao.SkuMapper;
import com.baizhi.entity.Sku;
import com.baizhi.entity.SkuExample;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Service("skuService")
@Transactional
public class SkuServiceImpl implements SkuService {

    @Resource
    private SkuMapper skuMapper;

    @Override
    public List<Sku> findAll() {
        SkuExample skuExample = new SkuExample();
        return skuMapper.selectByExample(skuExample);
    }

    @Override
    public Sku findById(String id) {
        return null;
    }

    @Override
    public List<Sku> findByProductId(String productId) {
        SkuExample skuExample = new SkuExample();
        skuExample.createCriteria().andProductidEqualTo(productId);
        return skuMapper.selectByExample(skuExample);
    }

    @Override
    public void save(Sku sku) {
        sku.setId(UUID.randomUUID().toString());
        skuMapper.insert(sku);
    }

    @Override
    public void update(Sku sku) {
        skuMapper.updateByPrimaryKeySelective(sku);
    }

    @Override
    public void delete(String id) {
        skuMapper.deleteByPrimaryKey(id);
    }
}
